﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Sockets;
using System.Runtime.Serialization.Formatters.Binary;
using System.Text;
using ConnectionObjects;

namespace TCPClient.RequestsToServerHandlers
{
    public class LoginHandler
    {
        private LoginObject m_LoginObject = new LoginObject();
        private NetworkStream m_Stream;

        public LoginHandler(string password, string username, NetworkStream stream)
        {
            m_LoginObject.Password = password;
            m_LoginObject.UserName = username;
            m_Stream = stream;
        }

        public OutConnectionObject LoginToServer()
        {
            BinaryFormatter binaryFormatter = new BinaryFormatter();
            binaryFormatter.Serialize(m_Stream, m_LoginObject);
            m_Stream.Flush();
            OutConnectionObject obj = (OutConnectionObject)binaryFormatter.Deserialize(m_Stream);
            return obj;
        }
    }
}
